<!doctype html>
<html lang="zh-CN">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
	<!-- Bootstrap -->
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
	<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
	<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
	<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
	<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>

	<title>个人信息</title>
	<link href="../file/images/dianmin.png" rel="shortcut icon" type="image/x-icon" />
	<link rel="stylesheet" type="text/css" href="../file/css/perInfo.css"/>
</head>

<body style="background-image: url(../file/images/1.jpg); ">
	<a href="../index.html"><img src="../file/images/11.png" title="首页" width="600px" height="700px"></a>
	<div class="box" >
	<h2>个人信息修改</h2>
	<form id="form1" onsubmit="return false" action="##" method="post">
		<div id="formDiv"></div>
		<button type="button" onclick="updatePer()" class="btn btn-primary btn-lg" style="display:block;margin:0 auto">更新</button>
	</form>
	</div>
</body>

<script src="../file/js/jquery-3.4.1.min.js" type="text/javascript"></script>
<script src="../file/js/jquery-ui.min.js" type="text/javascript"></script>
<script src="../file/js/slide.js" type="text/javascript"></script>
<script>
	//网页一加载 就要判断用户是否登录
	$(function () {
		ifLogin();
	})
	function ifLogin(){
		//开始发送请求 验证用户是否登录 然后打印个人信息
		$.ajax({
			url: "/user/showMemberInfo",
			type: "POST",
			success: function (data) {
				console.log(data);
				// if(data.code==200){
				// 	location.href="loginPage.html";
				// 	return;
				// }
				let str =	'';
				str =  `<div class="form-group">
						<label for="nickname">昵称：</label>
						<input type="text" name="nickname" class="form-control" id="nickname" placeholder="${data.memberinfo.nickname}" value="${data.memberinfo.nickname}">
						</div>
						<div class="form-group">
						<label for="pwd">密码：</label>
						<input type="password" name="pwd" class="form-control" id="pwd" placeholder="${data.memberinfo.pwd}" value="${data.memberinfo.pwd}">
						</div>
						<div class="form-group">
						<label for="tel">电话号码：</label>
						<input type="text" name="tel" class="form-control" id="tel" placeholder="${data.memberinfo.tel}" value="${data.memberinfo.tel}">
						</div>
						<div class="form-group">
						<label for="email">邮箱地址：</label>
						<input type="email" name="email" class="form-control" id="email" placeholder="${data.memberinfo.email}" value="${data.memberinfo.email}">
						</div>
						<div class="form-group">
						<label for="Address">收货地址：</label>
						<input type="text" name="Address" class="form-control" id="Address" placeholder="${data.memberinfo.address}" value="${data.memberinfo.address}">
						</div>`;
				$("#formDiv").html(str);
			}
		})
	}
	function exitLogin() {
		$.ajax({
			url: "/exitLogin" ,
			type: "GET",
			success: function () {
				location.href="../index.html";
			}
		})
	};
    function updatePer() {
        $.ajax({
            //几个参数需要注意一下
            type: "GET",//方法类型
            // dataType: "json",//预期服务器返回的数据类型
            url: "/user/UpdatePer" ,//url
            data: $('#form1').serialize(),
            success: function (result) {
            	console.log(result);
                if(result == 1) {
                	alert("修改成功！");
                	// location.href="index.html";
				}else if(result == -1){
                	alert("该用户名已存在！");
				}else {
					alert("异常！");
				}
				ifLogin();
            },
            error : function() {
                alert("异常！");
            }
        });
    }

</script>
</html>